-
Notifications
You must be signed in to change notification settings - Fork 205
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix the SIGQUIT handling system to deal with multiple ANRs properly. #1235
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a changelog entry.
Other nits mentioned below, but I'll leave the main functionality review for @fractalwrench as I'm not close-enough to the detail.
struct sigaction handler; | ||
sigemptyset(&handler.sa_mask); | ||
handler.sa_sigaction = handle_sigquit; | ||
handler.sa_flags = SA_SIGINFO; | ||
if (sigaction(SIGQUIT, &handler, &original_sigquit_handler) != 0) { | ||
if (sigaction(SIGQUIT, &handler, NULL) != 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the fact that we're not restoring the original handler here should be supported by some comments to justify this for future readers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a comment here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How will this work for environments such as Unity where ANR detection needs to be dynamically enabled/disabled via the Bugsnag.SetAutoNotify()
api?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When bugsnag is disabled, SIGQUIT is blocked and the default handler is never called. When bugsnag is enabled, our handler gets called. Either way, the default SIGQUIT handler never gets called in an Android app (and must never be called because it would terminate the app).
80f44ec
to
cb0768b
Compare
cb0768b
to
4c13f8d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm happy with these changes as long as they're tested out on a wide variety of devices. Added a question about Unity support inline.
struct sigaction handler; | ||
sigemptyset(&handler.sa_mask); | ||
handler.sa_sigaction = handle_sigquit; | ||
handler.sa_flags = SA_SIGINFO; | ||
if (sigaction(SIGQUIT, &handler, &original_sigquit_handler) != 0) { | ||
if (sigaction(SIGQUIT, &handler, NULL) != 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How will this work for environments such as Unity where ANR detection needs to be dynamically enabled/disabled via the Bugsnag.SetAutoNotify()
api?
Goal
Bugsnag wasn't handling things properly when multiple ANRs occur. This PR fixes it.
Design
The old handler would run once and exit, replacing the SIGQUIT handler with what was there before. This is the correct design for traditional signal handlers, but breaks in a Google ANR handler environment. Subsequent ANRs would trigger the default POSIX signal handler, which terminates the app.
Instead, we need the handler thread to run in a loop, blocking and unblocking SIGQUIT as necessary in order to coordinate with the Google ANR handler, and never setting the system to use the default handler.
Testing
These changes must be tested manually, which will happen on multiple devices at the beginning of the week. Do not merge until these tests are complete!